#include<bits/stdc++.h>
#define fi first
#define se second
#define il inline
using namespace std;
#define ll long long
#define INT __int128
#define ld long double
#define pb emplace_back
#define lb(x) ((x)&-(x))
#define pii pair<int,int>
#define ull unsigned long long
#define TIME clock()*1.0/CLOCKS_PER_SEC
il int pc(int x){return __builtin_popcount(x);}
il int pc(ll x){return __builtin_popcountll(x);}
template<typename T> il void chkmin(T& x,T y){if(x>y)x=y;}
template<typename T> il void chkmax(T& x,T y){if(x<y)x=y;}
string bin(int x){return x<=1?(x?"1":"0"):bin(x>>1)+(x&1?"1":"0");}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#define rand(x,y) uniform_int_distribution<ll>(x,y)(rng)
#ifndef ONLINE_JUDGE
#define debug(x) (cerr<<#x<<": "<<x<<endl)
void __file(string s){freopen((s+".in").c_str(),"r",stdin),freopen(((string)"kte.out").c_str(),"w",stdout);}
#undef DEBUG
#define DEBUG cerr<<"Passing ["<<__FUNCTION__<<"] in LINE "<<__LINE__<<endl
#else
#define debug(x) 0
#define __file(s) 0
#define DEBUG 0
#endif
const ll P=998244353;
ll qpow(ll x,ll y=P-2){ll z=1;while(y){if(y&1)z=z*x%P;x=x*x%P,y>>=1;}return z;}
#define int ll

int n;

set<int> s;
namespace BF{
	int bf(){
		if((int)s.size()<=1) return 0;
		int l,r;
		static vector<int> v;v.clear();v.pb(0);
		for(auto x:s) v.pb(x);
		int _=(int)v.size()-1;
		int i;
		l=r=-1;int ret=0;
		int sl=0,sr=0;
		for(i=1;i<_;i++){
			sl+=v[i],sr+=v[_+1-i];
			if(r<sl) ret+=r-l,l=sl,r=sr;
			else r=sr;
		}
		ret+=r-l;
		return ret;
	}
	int main(){
		while(n--){
			int x;cin>>x;
			if(s.count(x)) s.erase(x);
			else s.insert(x);
			cout<<bf()<<'\n';
		}
		return 0;
	}
}
namespace rnd{
	int main(){
		int ss=0;
		while(n--){
			int x;cin>>x;
			if(s.count(x)) s.erase(x),ss-=x;
			else s.insert(x),ss+=x;
			if((int)s.size()<=30) cout<<BF::bf()<<'\n';
			else cout<<ss-2**s.begin()<<'\n';
		}
		return 0;
	}
}
int32_t main(){
	__file("kte");
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	if(n<=1000) return BF::main();
	return rnd::main();
	return 0;
}
